﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PFWFA
{
    public partial class Browser1 : Form
    {
        Uri tempURL;

        public Browser1()
        {
            InitializeComponent();
        }

        private void btnGoURL_Click(object sender, EventArgs e)
        {
            wb1.Navigate(boxURL.Text);
        }

        private void wb1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            lblTitle.Text = wb1.DocumentTitle;
            tempURL = e.Url;
        }

        private void btnForward_Click(object sender, EventArgs e)
        {
            wb1.GoForward();
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            wb1.GoBack();
        }

        private void wb1_NewWindow(object sender, CancelEventArgs e)
        {
            e.Cancel = true;
            HtmlElement currentElement = wb1.Document.ActiveElement;
            string targetPath = currentElement.GetAttribute("href");
            wb1.Navigate(targetPath);
        }

        private void btnHome_Click(object sender, EventArgs e)
        {
            wb1.Navigate("http://google.com");
        }

        private void boxURL_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.Return)
            {
                wb1.Navigate(boxURL.Text);
            }
        }

    }
}
